package jiemian1;

import java.io.*;

//import com.alee.laf.WebLookAndFeel;
import moxing.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.SQLException;

import gonggong.*;
import gongju.*;
import user.Member;
import user.MemberManager;

public class Denglu extends JFrame implements ActionListener
{
    JLabel jbl1;
    JTabbedPane jtp;
    JPanel jp2,jp3,jp4;
    JLabel jp2_jbl1,jp2_jbl2,jp2_jbl3,jp2_jbl4;
    JButton jp2_jb1;
    JTextField jp2_jtf;
    JPasswordField jp2_jpf;
    JCheckBox jp2_jcb1,jp2_jcb2;
    JPanel jp1;
    JButton jp1_jb1,jp1_jb2,jp1_jb3;
    static Denglu dl;

    public static void main(String[] args)
    {
        dl=new Denglu();
    }
    public Denglu()
    {
        jbl1=new JLabel(new ImageIcon("C:\\Users\\Acer\\Desktop\\image\\tou.gif"));
        jp2=new JPanel(new GridLayout(3,3));
        jp2_jbl1=new JLabel("QQ号码",JLabel.CENTER);
        jp2_jbl2=new JLabel("QQ密码",JLabel.CENTER);
        jp2_jbl3=new JLabel("忘记密码",JLabel.CENTER);
        jp2_jbl3.setForeground(Color.blue);
        jp2_jbl4=new JLabel("申请密码保护",JLabel.CENTER);
        jp2_jb1=new JButton(new ImageIcon("C:\\Users\\Acer\\Desktop\\image\\clear.gif"));
        jp2_jtf=new JTextField();
        jp2_jpf=new JPasswordField();
        jp2_jcb1=new JCheckBox("隐身登录");
        jp2_jcb2=new JCheckBox("记住密码");
        jp2.add(jp2_jbl1);
        jp2.add(jp2_jtf);
        jp2.add(jp2_jb1);
        jp2.add(jp2_jbl2);
        jp2.add(jp2_jpf);
        jp2.add(jp2_jbl3);
        jp2.add(jp2_jcb1);
        jp2.add(jp2_jcb2);
        jp2.add(jp2_jbl4);
        jtp=new JTabbedPane();
        jtp.add("QQ号码",jp2);
        jp3= new JPanel();
        jtp.add("手机号码",jp3);
        jp4=new JPanel();
        jtp.add("电子邮件",jp4);
        jp1=new JPanel();
        jp1_jb1=new JButton(new ImageIcon("C:\\Users\\Acer\\Desktop\\image\\denglu.gif"));
        jp1_jb1.addActionListener(this);
        jp1_jb2=new JButton(new ImageIcon("C:\\Users\\Acer\\Desktop\\image\\wangji.jpg"));
        jp1_jb2.addActionListener(this);
        jp1_jb3=new JButton(new ImageIcon("C:\\Users\\Acer\\Desktop\\image\\xiangdao.gif"));
        jp1_jb3.addActionListener(this);
        jp1.add(jp1_jb1);
        jp1.add(jp1_jb2);
        jp1.add(jp1_jb3);
        this.add(jbl1,"North");
        this.add(jtp,"Center");
        this.add(jp1,"South");
        ImageIcon tp1=new ImageIcon("C:\\Users\\Acer\\Desktop\\image\\qq.gif");
        this.setIconImage(tp1.getImage());
        this.setTitle("用户登录");
        this.setSize(351,240);
        this.setLocation(300,280);
        this.setResizable(false);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
    }
    public void actionPerformed(ActionEvent e)
    {
        try {
            Class.forName("com.mysql.jdbc.Driver");

            if(e.getSource()==jp1_jb1)
            {

                Yanzheng yz=new Yanzheng();
                User u=new User();
                u.setUserId(jp2_jtf.getText().trim());
                u.setPasswd(new String(jp2_jpf.getPassword()));
                if(yz.checkUser(u)){

                    Message me=new Message();
                    //ObjectOutputStream oos=new ObjectOutputStream(s.getOutputStream());
                    //todo:把登录用户存入数据库，mysql,进行验证
                    Member msg = new Member();
                    msg.setUserId(u.getUserId());
                    msg.setPasswd(u.getPasswd());
                    System.out.println(msg.toString());
                    MemberManager memberManager = new MemberManager();
                    if (memberManager.userLogin(msg))
                    {
                        try {
                            liebiao lb=new liebiao(u.getUserId());
                            Glhylb.addliebiao(u.getUserId(),lb);
                            ObjectOutputStream oos=new ObjectOutputStream
                                    (Glxc.getLjfwqxc(u.getUserId()).getS().getOutputStream());
                            Message m=new Message();
                            m.setMesType(MessageType.message_get_onLineFriend);
                            m.setSender(u.getUserId());
                            oos.writeObject(m);

//
                            JFrame frame = new JFrame("qunliao");
                            qunliao liao=new qunliao(u);
                            frame.setContentPane(liao.Jpanel1);
                            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                            frame.pack();
                            frame.setVisible(true);
                            frame.setSize(600,600);
                            frame.setLocation(700,200);
                            lb.setSize(200,600);
                            lb.setLocation(1300,200);

//                            Glxc.getLjfwqxc(u.getUserId()).setMessageArea(liao.messArea);
//                            liao.recv.run();
                        } catch (Exception e3){}
                        this.dispose();
                    }}
                else{
                    JOptionPane.showMessageDialog(this,"用户名或密码错误");
                }
            } } catch (ClassNotFoundException | SQLException ex) {
            ex.printStackTrace();
        }
        if(e.getSource()==jp1_jb3){

            JFrame frame1 = new JFrame("注册");
            frame1.setContentPane(new Register(frame1).registerpane);
            frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame1.setBounds(((Toolkit.getDefaultToolkit().getScreenSize().width)/2)-300,
                    ((Toolkit.getDefaultToolkit().getScreenSize().height)/2)-300,600,600);
            frame1.pack();
            frame1.setVisible(true);
            frame1.setSize(500,300);
         }
        if(e.getSource()==jp1_jb2){
            JFrame frame=new JFrame("验证密保");
            frame.setContentPane(new findpass(frame).find);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setBounds(((Toolkit.getDefaultToolkit().getScreenSize().width) / 2) - 300,
                    ((Toolkit.getDefaultToolkit().getScreenSize().height) / 2) - 300, 600, 600);
            frame.pack();
            frame.setVisible(true);
            frame.setSize(500,300);
        }
    }
}
